import { fileURLToPath, URL } from 'node:url'
import { viteMockServe } from 'vite-plugin-mock'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// 使用jsx时开启
// import vueJsx from '@vitejs/plugin-vue-jsx'

// https://vitejs.dev/config/
export default defineConfig({
  define: {
    // enable hydration mismatch details in production build
    __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'true'
  },
  plugins: [
    vue(),
    // 使用jsx时开启
    // vueJsx(),
    viteMockServe({ supportTs: false }),
    // AutoImport({
    //   // resolvers: [ElementPlusResolver()],
    //   // 自动导入vue相关函数
    //   imports: ['vue', 'vue-router'],
    //   dts: './auto-imports.d.ts',
    // }),
    // Components({
    //   resolvers: [ElementPlusResolver()],
    //   globs: ['src/components/*/index.*'],
    //   dts: './components.d.ts'
    // })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  // 引入sass全局样式变量
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@import "@/assets/scss/basic.scss";`
      }
    }
  },
  //启动服务配置
  server: {
    host: '0.0.0.0',
    port: 88,
    open: true,
    https: false,
    cors: true,
    proxy: {
      '/api': {
        target: 'http://127.0.0.1:5566', // easymock
        changeOrigin: true,
        // rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  }
})
